/** 
 * UIMA Annotation Mapper
 * Copyright (C) 2010  Nicolas Hernandez
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package fr.univnantes.lina.uima.mapper.annotation.located;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.cas.text.AnnotationIndex;
import org.apache.uima.jcas.tcas.Annotation;

/**
 * @author hernandez
 *
 */
public class LocatedAnnotationIndex  {

	/*
	 * Membres
	 */
	/**
	 * Map which associates for each offset (handled as a string) the corresponding LocatedAnnotation
	 */
	private Map<String, LocatedAnnotation> locatedAnnotationMap;
	
	/**
	 * Map which associates for each offset begin a list of corresponding annotation
	 */
	private Map<Integer,List<Annotation>> annotationBeginMap; // TreeMap the key are the begin offset and the value are arraylist of annotations
	
	/**
	 * Map which associates for each offset end a list of corresponding annotation
	 */
	private Map<Integer,List<Annotation>> annotationEndMap;

	// index des types ? des tailles ? arbre des inclusions

	/*
	 * Constructeurs
	 */
	/**
	 * Initialize any index structures
	 */
	public LocatedAnnotationIndex () {
		this.setLocatedAnnotationMap(new HashMap<String, LocatedAnnotation>());
		this.setAnnotationBeginMap(new HashMap<Integer, List<Annotation>>());
		this.setAnnotationEndMap(new HashMap<Integer, List<Annotation>>());
	}
	
	/**
	 * Initialize any index structures
	 */
	public LocatedAnnotationIndex (HashMap<String, LocatedAnnotation> locatedAnnotationMap, 
			HashMap<Integer, List<Annotation>> beginMap, 
			HashMap<Integer, List<Annotation>> endMap) {
		this.setLocatedAnnotationMap(locatedAnnotationMap);
		this.setAnnotationBeginMap(beginMap);
		this.setAnnotationEndMap(endMap);
	}
	
	/*
	 * Getter / Setter
	 */
	/**
	 * @return the locatedAnnotationMap
	 */
	public Map getLocatedAnnotationMap() {
		return locatedAnnotationMap;
	}
	
	/**
	 * @param locatedAnnotationIndex the locatedAnnotationIndex to set
	 */
	public void setLocatedAnnotationMap(Map locatedAnnotationMap) {
		this.locatedAnnotationMap = locatedAnnotationMap;
	}
	

	/**
	 * @return the annotationBeginMap
	 */
	public Map<Integer, List<Annotation>> getAnnotationBeginMap() {
		return annotationBeginMap;
	}

	/**
	 * @param annotationBeginMap the annotationBeginMap to set
	 */
	public void setAnnotationBeginMap(
			Map<Integer, List<Annotation>> annotationBeginMap) {
		this.annotationBeginMap = annotationBeginMap;
	}

	/**
	 * @return the annotationEndMap
	 */
	public Map<Integer, List<Annotation>> getAnnotationEndMap() {
		return annotationEndMap;
	}

	/**
	 * @param annotationEndMap the annotationEndMap to set
	 */
	public void setAnnotationEndMap(Map<Integer, List<Annotation>> annotationEndMap) {
		this.annotationEndMap = annotationEndMap;
	}
	

	/*
	 * Other methods
	 */
	
	/**
	 * 
	 * @param annotationOffset
	 * @return
	 */
	public LocatedAnnotation getLocatedAnnotation(String annotationOffset) {
		// TODO test if LocatedAnnotationMap exists and not empty
		return (LocatedAnnotation) getLocatedAnnotationMap().get(annotationOffset);
	}

	/**
	 * Check if a LocatedAnnotation at some offset has been created
	 * @param annotationOffset
	 * @return
	 */
	public boolean existsLocatedAnnotation(String annotationOffset) {
		// TODO test if LocatedAnnotationMap exists and not empty
		return getLocatedAnnotationMap().containsKey(annotationOffset);
	}
	

}
